﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Windows;
using Fluent;
using PefStudio.Base;
using PefStudio.StartUp;

namespace PefStudio.Windows
{
    public class AbstractRibbonBackstage : Backstage, IRibbonBackstage, IPartImportsSatisfiedNotification
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Window))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        protected string BaseContract{ get; set; }
        public virtual void OnImportsSatisfied()
        {
            if (Content == null)
            {
                Content = new BackstageTabControl();
            }
            var backstageTabControl = Content as BackstageTabControl;
            if (backstageTabControl == null) return;
            try
            {
                var children =
                    MainWindow.CompositionContainer.GetExportedValues<IRibbonChildItem>(BaseContract);
                CreateService.CreateCollection(backstageTabControl.Items, children);
            }
            catch (ImportCardinalityMismatchException)
            {
            }
        }
    }

    public class AbstractRibbonQuickAccessMenuItem : QuickAccessMenuItem, IRibbonQuickAccessMenuItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Window))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }
    }
}
